import pandas as pd
import numpy as np
import re
import csv
import sys
from datetime import date
import time

df = pd.read_csv('gaze.csv', encoding='utf-8')
#df = df.astype(str)

df_clear = df.drop(df[(df['confidence']<0.9)].index) #删除confidence小于0.9的数据

num_x = df['norm_pos_x'] #利用3sigma原则筛选出符合条件的数

left=num_x.mean()-3*num_x.std()
right=num_x.mean()+3*num_x.std()

new_num_x=num_x[(left<num_x)&(num_x<right)]
print(new_num_x)
print(len(new_num_x))

num_y = df['norm_pos_y']

left=num_y.mean()-3*num_y.std()
right=num_y.mean()+3*num_y.std()

new_num_y=num_y[(left<num_y)&(num_y<right)]
print(new_num_y)
print(len(new_num_y))

#改变时间戳


#获取当前时间
time_now = int(time.time())
#转换成localtime
time_local = time.localtime(time_now)

dt = time.strftime("%Y-%m-%dT%H:%M:%S.225707+0000",time_local)

print(dt)

#df1 = df.astype(str)
#for t in df1['gaze_timestamp']:
#    print(datetime.datetime.date(t))

#采样率偏差
length = len(df['gaze_timestamp'])
data4 = df['gaze_timestamp']
max_time = max(data4)
min_time = min(data4)
mean_time = (max_time - min_time)/length
sampling_rate = 1/mean_time
print(sampling_rate)

#gaze_timestamp按照100HZ的帧率重新采样

df['gaze_timestamp'] = pd.to_datetime(df['gaze_timestamp'].values, unit='ms')
df = df.resample('10ms', on='gaze_timestamp').mean()
print(df[0: 20])




